package com.zuxia.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.zuxia.dao.ITitleDao;
import com.zuxia.entity.Title;

@Repository("titleDao")
public class TitleDao implements ITitleDao{
	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	@SuppressWarnings("unchecked")
	public List<Title> findAll() {
		return (List<Title>) hibernateTemplate.find("from Title");
	}
	public void saveTitle(Title title) {
		hibernateTemplate.save(title);
	}
	public void updateTitle(Title title) {
		SessionFactory factory = hibernateTemplate.getSessionFactory();
		Session session = factory.getCurrentSession();
		Title title2 = session.get(Title.class,title.getTitleId());
		title2.setTitleName(title.getTitleName());
		title2.setTitleIndustry(title.getTitleIndustry());
		title2.setTitleTime(title.getTitleTime());
		title2.setTitleUptime(title.getTitleUptime());
		title2.setTitleText(title.getTitleText());
		session.saveOrUpdate(title2);
	}
	public void deleteTitle(Title title) {
		SessionFactory factory = hibernateTemplate.getSessionFactory();
		Session session = factory.getCurrentSession();
		Title title2 = session.get(Title.class,title.getTitleId());
		session.delete(title2);
		
	}
	@SuppressWarnings("unchecked")
	public List<Title> selectTitle1(Title title) {
		return (List<Title>) hibernateTemplate.find("from Title where titleId="+title.getTitleId());
	}
	@SuppressWarnings("unchecked")
	public List<Title> selectTitle2(String titleindustry) {
		return (List<Title>) hibernateTemplate.find("from Title where titleIndustry=?",titleindustry);
	}

}
